package com.sxj.corejava.code07_面向对象.bms;

/**
 * @author 石小俊
 * @date 2024年03月26日 18:54
 */
public class LoanCreditAccount extends CreditAccount implements Loanable {

    private double loanAmount;  // 贷款总金额

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    @Override
    public void providerLoan(double money) {
        loanAmount += money;
    }

    @Override
    public boolean payLoan(double money) {
        // 对于贷款的信用账户,只有当账户余额 + 可透支额度 >= 还款金额时才能成功还款
        if (getBalance() + getLimit()>= money) {
            // 还款后账户余额减少
            setBalance(getBalance() - money);
            // 贷款总金额减少
            loanAmount -= money;
            return true;
        }
        return false;
    }

    @Override
    public double queryLoan() {
        return loanAmount;
    }
}
